Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4963 - SVG <use> swallows click events #5720

Merged
merged 1 commit into from
Feb 17, 2016
Merged

Conversation

edmellum
Copy link
Contributor

Info about the issue in #4963

This fix uses the corresponding <use> element as the target of a click handler instead of the <svg> it refers to, thereby normalizing the behavior of IE, Edge and iOS to the behavior of Chrome. Without this fix there is no way to handle click events on <use> elements in the aforementioned browsers as their target becomes the referred to <svg> which may be far outside of the attached click handler causing it to be dropped.

@wnr
Copy link

wnr commented Feb 12, 2016

This is a bug that we are experiencing in our team as well. I have verified that your solution works. I hope that this will be merged asap.

@jimfb
Copy link
Contributor

jimfb commented Feb 12, 2016

Looks legit to me, cc @spicyj for sanity check.

@@ -20,6 +20,12 @@
*/
function getEventTarget(nativeEvent) {
var target = nativeEvent.target || nativeEvent.srcElement || window;

// Normalize SVG <use> element events #4963
if (target.correspondingUseElement && !target.nodeType) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is target such that it doesn't have a nodeType?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems to me like the !target.nodeType doesn't to anything really. If the target has a correspondingUseElement property, the target must be an instance of SVGElementInstance and lives in the shadow DOM. Such elements do not have a nodeType property, and therefore it will always be falsy. Perhaps the check is present for some weird browser bugs? @edmellum

https://www.w3.org/TR/SVG/single-page.html#struct-__svg__SVGElementInstance__correspondingUseElement

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've looked over and retested everything. !target.nodeType is a relic from my exploration during early implementation that only partially solved the issues on IE, whereas correspondingUseElement properly solves it. I'll remove it and rebase onto the current commit so there's no noise to merge.

@edmellum
Copy link
Contributor Author

As mentioned in the line notes I've fixed the !target.nodeType issue, looked over and retested everything.

@facebook-github-bot
Copy link

@edmellum updated the pull request.

jimfb added a commit that referenced this pull request Feb 17, 2016
Fix #4963 - SVG <use> swallows click events
@jimfb jimfb merged commit c9e0fc7 into facebook:master Feb 17, 2016
@jimfb
Copy link
Contributor

jimfb commented Feb 17, 2016

Thanks @edmellum!

@wnr
Copy link

wnr commented Feb 17, 2016

👍

@ghost
Copy link

ghost commented Feb 17, 2016

I don't understand this crap
On Feb 12, 2016 11:36 AM, "Lucas Wiener" notifications@github.com wrote:

This is a bug that we are experiencing in our team as well. I have
verified that your solution works. I hope that this will be merged asap.


Reply to this email directly or view it on GitHub
#5720 (comment).

@jimfb
Copy link
Contributor

jimfb commented Feb 17, 2016

@shastings86 care to elaborate? Also, please watch your attitude; at first glance, your comment appears to be very negative and not constructive - which is not the type of community we want to foster.

@ghost
Copy link

ghost commented Feb 18, 2016

I can't read it

On February 17, 2016, at 12:37 PM, Jim notifications@github.com wrote:

@shastings86 care to elaborate? Also, please watch your attitude; at first glance, your comment appears to be very negative and not constructive - which is not the type of community we want to foster.


Reply to this email directly or view it on GitHub.

@justo
Copy link

justo commented Feb 21, 2017

Thank you for this fix! It was a strange bug that took us a while to find.

@justo justo unassigned jimfb Feb 21, 2017
@aweary
Copy link
Contributor

aweary commented Feb 21, 2017

@justo just curious, but did you actually unassign @jimfb ^?

@justo
Copy link

justo commented Feb 21, 2017

I have no idea, as soon as I posted the comment that showed up...

@aweary
Copy link
Contributor

aweary commented Feb 21, 2017

@justo thanks, I've seen it a couple other times recently. It looks like its potentially a bug with Github.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants